{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "Finding the closest object in the feature space"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    " \n",
    "from sklearn.metrics import pairwise\n",
    "from sklearn.datasets import make_blobs\n",
    "points, labels = make_blobs()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.,  0.,  0.,  0.,  0.])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distances = pairwise.pairwise_distances(points)\n",
    "np.diag(distances) [:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0.        ,   3.57728617,   8.0578449 ,  10.46005061,  18.80775551])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distances[0][:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0, 10, 40, 89, 93], dtype=int64)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ranks = np.argsort(distances[0])\n",
    "ranks[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-8.51113774, -6.65692628],\n",
       "       [-7.70001496, -6.15465225],\n",
       "       [-8.01917359, -5.47174318],\n",
       "       [-8.48100837, -5.3246355 ],\n",
       "       [-8.18974541, -5.21185281]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "points[ranks][:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.legend.Legend at 0xa3418d0>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAGnCAYAAABrSimNAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt4VNW9//HPyg0mkEQCMdwTK4Jo0YIGxUtNVEpFBfVn\nFWwpldSKAnKktXKAFvDUqrSi1VMrUiriMRG1LYpioVjgcPNABUUEBC8JCGgiCERMSELW749cSGCS\nzCR7svdM3q/nyfNkZvbM/s6GTD5Za+3vNtZaAQAAwDlRbhcAAAAQaQhYAAAADiNgAQAAOIyABQAA\n4DACFgAAgMMIWAAAAA5zJGAZY+YZY74wxmypdd90Y8xnxphNVV/fd2JfAAAAXufUCNazkob4uX+2\ntXZA1dc/HNoXAACApzkSsKy1ayR95ech48TrAwAAhJNQr8Eab4x51xjzZ2NMUoj3BQAA4AnGqUvl\nGGPSJC221p5XdTtF0pfWWmuM+Y2kLtbabD/P41o9AAAgbFhrG52hC9kIlrW20J5Ib3MlZTSwLV8n\nfU2fPt31Grz4xXHhuHBMOC4cF46Lm1+BcjJgGdVac2WM6VzrsZskbXVwXwAAAJ4V48SLGGNyJGVK\n6miM2S1puqQsY8x3JFVIypN0pxP7AgAA8DpHApa19jY/dz/rxGu3VpmZmW6X4EkcF/84LqfimPjH\ncfGP4+Ifx6XpHFvk3uQCjLFu1wAAABAIY4xsAIvcHRnBAgAgEqWnpys/P9/tMuCCtLQ05eXlNfn5\njGABAFCPqtEKt8uAC+r7tw90BIuLPQMAADiMgAUAAOAwAhYAAIDDCFgAAAAOI2ABABCBbr/9dv36\n17+WJK1atUo9evRwfB933XWXHnzwQcdfNxIQsAAACGOZmZlKTk5WWVlZg9sZU/+Jb1FRUUpISFBi\nYqJ69Oihn//85wGdPfmnP/1JU6dODajO2oGvNSBgAQDgsIMHD2ro0B8oKamLevXqr9WrV4dkP/n5\n+VqzZo2ioqL02muvNfl1jDHasmWLjhw5orfeeks5OTmaO3eug5W2PgQsAACCtHbtWvXrd4k6dz5L\no0eP1TfffFPn8WHDRmr58tN15MhGffzxdF1zzU2nNK0sKSnRkiVL9Oqrr+rQoUNNqmPBggUaNGiQ\nfvKTn2j+/PlNfDeStbZmxKp37966/PLLtXXrVknS9u3blZWVpQ4dOqhfv35avHhxzfP8TUPOnj1b\nqamp6tatW01Nc+fO1QsvvKBZs2YpMTFRw4cPlyQ98sgj6t69uxITE9W3b1+tWLGiye/Ba+jkDgBA\nED766CMNGXKDjh79o6R+eumlX6uo6Gf629/+R5J07NgxrV+/QhUVb6jy12x3GfOyVq1apfT0dEnS\n4cOHNXBglvbv90lqr7Zt79H//d9KnXHGGUHVsmDBAv3iF79QRkaGLr74YhUWFiolJaVZ72/btm1a\nvXq1HnroIZWXl2vYsGH66U9/qn/+859avXq1hg8frnfeeUdnnXXWKc/9/PPPVVRUpH379mnZsmW6\n+eabdeONN+qOO+7QunXr1KNHDz3wwAOSpJ07d+qPf/yj3nnnHaWmpmr37t06fvx4s2r3EkawAAAI\nwtKlS3X8+I2SbpHUVyUl87R48V9rRoBiY2MVExMnaU/VMyok5SkpKanmNR58cJby8s5XUdEaFRUt\n1YEDYzVu3P1B1bFmzRrt3r1bt9xyiwYMGKBevXopJyenye9rwIAB6tixo4YPH66f/exn+slPfqK3\n335bR48e1f3336+YmBhlZWXpuuuuU25urt/XiIuL069+9StFR0frmmuuUfv27fXhhx/63TY6Olql\npaXaunWrysvL1bNnz6ADppcRsAAACEK7du0UHb2/1j371aZNfM0i8qioKD300G8VH3+ljPm14uOv\nU58+MRo6dGjNMz76aI9KS78rqfI5FRWXKy9vj4KxYMECfe9731OHDh0kSSNHjtRzzz3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SM0ejRo7V//34VFBT43TY2NlZFRUXatm2brLXq06eP\nUlNTA645GAQsAACC0a6dFB1d9742baTqBeVRUdJDD0nx8ZX3xcdLffpUrsmq9tFHUmnpidsVFadO\nITagY8eO+vLLL1VRURHQ9vv27VNaWlrNbWOMevToob179+rMM8/U448/rhkzZig1NVW33XabPv/8\nc0mVi9FvvPFGJScnKzk5Weecc45iY2P1xRdfaNSoURoyZIhGjBih7t276/7779fx2sGzEcYYHThw\nQAcOHNAHH3ygcVUB8+RapcoQtXfvXr+v07lz55rvfT6fJOnrr7/2u21WVpbGjx+vcePGKTU1VWPH\njq132+YiYAEAEIybb5ZSU6W4uMrb8fGVI1K1TZokLVokTZsmPfpo5Zqt6u0lKTOz8nnV2raVLr88\n4BIGDRqkNm3aaNGiRQFt37VrV+Xn59e5b8+ePerWrZskacSIEVq9enXNNvfff78kqWfPnnrzzTd1\n8OBBHTx4UF999ZWOHj2qLl26KCYmRr/61a/0wQcfaN26dXr99de1YMECSYGfvWirR/1OqjXvpLC5\ne/fumlqD4a+O8ePH69///re2bdumDz/8UL/73e+Cft1AELAAAAhG+/bSpk3S9OnShAnSSy9JEyee\nut3gwdIDD0hjx1aOcNU2frw0YkTlVGJsrHTppdLs2QGXkJiYqJkzZ2rcuHF69dVXVVxcrPLycr35\n5puaPHnyKdvfcssteuONN7RixQqVl5fr97//vdq2batLLrlEO3fu1IoVK1RaWqq4uDj5fL6aqcc7\n77xTU6ZM0e7duyVJhYWFNWcprly5Ulu3blVFRYXat2+v2NhYRVeN7KWmpuqTTz5p8D34C1dSZZ+r\nXbt26cUXX9Tx48e1cOFCbd++Xddff33Ax6fayXX8+9//1oYNG1ReXi6fz6e2bdsGPM0atEAWaoXy\nSyxyBwB4VMh/R339deWC9ybKycmxF154oW3fvr3t0qWLve666+z69euttXUXuVtr7aJFi+w555xj\nTzvtNJuZmWm3bdtmrbV2y5YtduDAgTYxMdF27NjRXn/99Xb//v3WWmsrKirsY489Zvv06WMTExNt\nr1697NSpU6211ubm5to+ffrY9u3b286dO9v/+I//qFl0v379etu7d2+bnJxsJ06ceErd1Yvc61uk\nv3btWnvBBRfY0047zV544YV23bp1NY9lZWXVWeR++eWX13luVFSU/fjjj/3W8dZbb9nzzjvPJiQk\n2JSUFPujH/3IHj161G8N9f3bK8BF7sbWkyBbijHGul0DAAD+GGPqHWlBZKvv377q/kbnQJkiBAAA\ncBgBCwAAwGEELAAAAIcRsAAAABxGwAIAAHAYAQsAAMBhBCwAAACHEbAAAAAcRsACACACzZw5U6NG\njXK7jJBISEg45XqFXkPAAgAgTOXk5CgjI0MJCQnq1q2brr32Wq1bt67m8UAvuuyG5557TjExMUpM\nTNRpp52mAQMG6I033gjouUVFRUpPTw9o26ioqEavixgKBCwAABx2sPighr4wVEkPJ6nXE720On+1\n4/uYPXu2Jk2apGnTpqmgoEC7d+/WuHHjai7GHA4uueQSHTlyRIcOHdKYMWN0yy236PDhw47uw62Q\nScACACBIa3evVb+n+qnz7ztr9N9H65uyb+o8Pix3mJZ/slxHjh3Rx199rGteuEZ5h/LqbFNSXqIl\nu5bo1R2v6lDJoaD2f+TIEU2fPl1PPfWUhg8fLp/Pp+joaA0dOlQPP/xwzXbHjh3T6NGjlZiYqH79\n+mnTpk01j+3YsUNZWVnq0KGD+vXrp8WLF9c8tmTJEp177rlKTExUjx49NHv27JrHXn/9dfXv318d\nOnTQZZddpvfff7/msTPOOEOPPvqozj//fHXo0EEjR45UaWlpQO9pzJgxKi4u1scffyxJmjt3rs46\n6yx16tRJN9xwg/bv31+zbe1Rqdtvv13jx4/Xddddp8TERA0aNEiffvqpJOmKK66QtVbnnXeeEhMT\n9fLLLwdzmJuFgAUAQBA+OviRhvzPEG0t3Kovjn6hlz54ST/6249qHj9WfkzrP1uvsoqymvuMMVqV\nt6rm9uGSwzr/6fM14pURGvX3Uer9ZG99+tWnAdewfv16HTt2TDfccEOD2y1evFi33XabDh8+rOuv\nv17jxo2TJJWXl+v666/X97//fRUWFuqJJ57QD3/4Q+3at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0iuq/Lz92u163GaMuVbS\nF9bad6uWZLSaz5NGxEgaIGmctfbfxpjHJU1W5RIevxuHTKiblEaCho6RMeZ5a+3Equ1eMcbMa7nK\n3NXIcRkr6W9V222sWtTd0Vp7oMUKdEF9x8QY821J6ZLeq1qv2F3SO8aYgdbaghYs0RWNfc4YY36i\nyqmOK1ukIO/aK6lnrdsR/dkaKGNMjCrD1fPW2lfdrscjLpU0zBgzVJJPUoIxZoG19scu1+W2z1Q5\nU/DvqtuvSKr3ZBGvTBHSpNS/vcaYKyTJGHOVpJ0u1+MVi1T1y9IY01tSbKSHq4ZYa7daaztba79l\nrT1DlR8C/VtDuGqMMeb7qpzmGGatPeZ2PS7bKKmXMSbNGBMnaYQqP29bu79I2mat/YPbhXiFtXaK\ntbantfZbqvx/8i/ClWSt/ULSnqrfO5J0lRo4CSCkI1gNMcbcIOlJSZ1U2aT0XWvtNdbabcaY6ial\nZWrdTUrvkPSEMSZaUomkn7lcj1c8K+kvxpj3JR2T1Op/8E9ixZB+tSclxUn6Z9XJyG9ba+92tyR3\nWGuPG2PGq/LMyihJ86y19Z4B1RoYYy6V9ENJ7xtjNqvyZ2eKtfYf7lYGD7tH0gvGmFhJn0i6vb4N\naTQKAADgMK9MEQIAAEQMAhYAAIDDCFgAAAAOI2ABAAA4jIAFAADgMAIWAACAwwhYAAAADvv/muqZ\nKgyeJL8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xa4993c8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline\n",
    "\n",
    "sp_points = points[ranks][:5]\n",
    " \n",
    "plt.figure(figsize=(10,7))\n",
    "plt.scatter(points[:,0], points[:,1], label = 'All Points')\n",
    "plt.scatter(sp_points[:,0],sp_points[:,1],color='red', label='Closest Points')\n",
    "plt.scatter(points[0,0],points[0,1],color='green', label = 'Chosen Point')\n",
    " \n",
    "plt.legend()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5772861690201232"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def euclid_distances(x, y):\n",
    "     return np.power(np.power(x - y, 2).sum(), .5)\n",
    "    \n",
    "euclid_distances(points[0], points[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  0.,  10.])"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pairwise.pairwise_distances([[0, 0], [5, 5]], metric='cityblock')[0]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[False,  True, False,  True],\n",
       "       [False,  True,  True,  True]], dtype=bool)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = np.random.binomial(1, .5, size=(2, 4)).astype(np.bool)\n",
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.  ,  0.25],\n",
       "       [ 0.25,  0.  ]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pairwise.pairwise_distances(X, metric='hamming')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
